package com.hnevc.androidhomework4;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {
    private static final String TAG ="MainActivity2" ;
    EditText mEtName;
    TextView mTvText ,mTv_shulang;
    CheckBox mCb_la,mCb_su,mCb_suan,mCb_hun;
    Button mBtn_ok;
    ImageView mTvImage;
    SeekBar mSbProce;
    int id;
    protected void OnCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        mEtName = (EditText) findViewById(R.id.et_name);
        Intent intent = getIntent();
        String data = intent.getStringExtra("name");
        mEtName.setText(data);

        mTv_shulang = (TextView) findViewById(R.id.tv_shulang);
        mBtn_ok = (Button) findViewById(R.id.btn_ok);
        mSbProce = (SeekBar) findViewById(R.id.sb_proce);
        mTvText = (TextView) findViewById(R.id.tv_text);
        mCb_hun = (CheckBox) findViewById(R.id.cb_hun);
        mCb_la = (CheckBox) findViewById(R.id.cb_la);
        mCb_su = (CheckBox) findViewById(R.id.cb_su);
        mCb_suan = (CheckBox) findViewById(R.id.cb_suan);
        mTvImage = (ImageView) findViewById(R.id.tv_Image);
        mSbProce.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){


            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mTv_shulang.setText(Integer.toString(progress)+"元");
                id = Integer.parseInt(String.valueOf(progress));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Log.e("------------", "onStartTrackingTouch: 开始拖动");
                Log.e(TAG, "onStartTrackingTouch: " );
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Log.e("------------", "onStopTrackingTouch: 停止滑动");
            }
        });
        mBtn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean la = mCb_la.isChecked();
                boolean su = mCb_su.isChecked();
                boolean suan = mCb_suan.isChecked();
                boolean hun = mCb_hun.isChecked();
                TextView viewById = (TextView) findViewById(R.id.tv_shulang);
                String price = viewById.getText().toString();
                mTvText = (TextView) findViewById(R.id.tv_text);
                mTvImage =(ImageView) findViewById(R.id.tv_Image);

                Log.e(TAG, "onClick: "+price );
                if ((suan && la && su)){
                    if(id <=15){
                        mTvText.setText("桂林米粉");
                        mTvImage.setImageResource(R.mipmap.guilin);
                    }else if(id<=40){
                        mTvText.setText("酸辣汤");
                        mTvImage.setImageResource(R.mipmap.suanlatang);
                    }
                }else if (la && hun){
                    if (id<=48){
                        mTvText.setText("水煮鱼");
                        mTvImage.setImageResource(R.mipmap.shuizhuyu);
                    }else if (id<=55){
                        mTvText.setText("麻辣香锅");
                        mTvImage.setImageResource(R.mipmap.malaxiangguo);
                    }else if (id<=80){
                        mTvText.setText("麻辣火锅");
                        mTvImage.setImageResource(R.mipmap.malahuoguo);
                    }
                }
            }
        });
    }


}